import { ILoadMapTypeAll, ISearchTranslateAll } from '@/common';
import { getBaseUrl } from '@/services/urlconst';
import { getTenantID, getUserID, requestFunComponFiex } from '@/utils';
import { useRequest } from 'umi';

const baseUrl = getBaseUrl();

/**
 * 获取详情
 * @param callback  获取详情回调
 * @returns
 */
const getWarnByIDService = (callback: (res: any) => void) => {
  /**  需要获取的数据字典 */
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}`, //工单类型
  ];

  const getWarnByID = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/warnController/getMwarnByID`;
      const payload: Record<string, any> = {
        ...params,
        dicTypeIds: loadMdicIds?.toString(),
        dicTransName: 'orderType',
        orgTransName: `${ISearchTranslateAll.OWNER_DEPT}`,
        ownerID: getUserID(),
      };
      return requestFunComponFiex('PUT', personUrl, payload);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );

  return {
    getWarnByIDRun: getWarnByID?.run,
    getWarnByIDLoading: getWarnByID?.loading,
    getWarnByIDInfo: getWarnByID?.data?.obj,
  };
};

/**
 *  设置已读
 * @param callback  设置已读回调
 * @returns
 */
const getWarnSetReadService = (callback: (res: any) => void) => {
  /**  需要获取的数据字典 */
  const loadMdicIds: string[] = [
    `${getTenantID()}${ILoadMapTypeAll.ALLORDER_TYPE}`, //工单类型
  ];

  const getWarnSetRead = useRequest(
    (params: any) => {
      let personUrl = `${baseUrl}/warnController/setRead`;
      const payload: Record<string, any> = {
        ...params,
        dicTypeIds: loadMdicIds?.toString(),
        dicTransName: 'orderType',
        orgTransName: `${ISearchTranslateAll.OWNER_DEPT}`,
        ownerID: getUserID(),
        readFlag: 1,
      };
      return requestFunComponFiex('PUT', personUrl, payload);
    },
    {
      manual: true,
      onSuccess: callback,
    },
  );

  return {
    getWarnSetReadRun: getWarnSetRead?.run,
    getWarnSetReadLoading: getWarnSetRead?.loading,
  };
};

export { getWarnByIDService, getWarnSetReadService };
